package cn.edu.ncu.housinghub.controller.maintenance;

import cn.edu.ncu.housinghub.dto.request.maintenance.MaintenanceRequest;
import cn.edu.ncu.housinghub.service.MaintenanceService;
import cn.edu.ncu.housinghub.vo.Result;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 维修申请控制器
 */
@RestController
@RequestMapping("/maintenance")
public class MaintenanceController {
    
    @Autowired
    private MaintenanceService maintenanceService;
    
    /**
     * 租客申请维修
     */
    @PostMapping("/tenant/apply")
    public Result applyMaintenance(@Valid @RequestBody MaintenanceRequest request, 
                                 @RequestHeader("info") String token) {
        return maintenanceService.applyMaintenance(request, token);
    }
    
    /**
     * 租客查看维修申请列表
     */
    @GetMapping("/tenant/list")
    public Result getTenantMaintenanceList(@RequestHeader("info") String token) {
        return maintenanceService.getTenantMaintenanceList(token);
    }
    
    /**
     * 房东查看维修申请列表
     */
    @GetMapping("/landlord/list")
    public Result getLandlordMaintenanceList(@RequestHeader("info") String token) {
        return maintenanceService.getLandlordMaintenanceList(token);
    }
    
    /**
     * 房东处理维修申请
     */
    @PutMapping("/landlord/handle/{maintenanceId}")
    public Result handleMaintenance(@PathVariable Long maintenanceId,
                                  @RequestParam Integer status,
                                  @RequestParam(required = false) String remark,
                                  @RequestHeader("info") String token) {
        return maintenanceService.handleMaintenance(maintenanceId, status, remark, token);
    }
    
    /**
     * 获取维修申请详情
     */
    @GetMapping("/detail/{maintenanceId}")
    public Result getMaintenanceDetail(@PathVariable Long maintenanceId,
                                     @RequestHeader("info") String token) {
        return maintenanceService.getMaintenanceDetail(maintenanceId, token);
    }
}
